package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.HouseTable;
import com.lineage.server.datatables.storage.HouseStorage;
import com.lineage.server.templates.L1House;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class HouseReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final HouseStorage _storage = (HouseStorage)new HouseTable();
  
  private static HouseReading _instance;
  
  public static HouseReading get() {
    if (_instance == null)
      _instance = new HouseReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public Map<Integer, L1House> getHouseTableList() {
    Map<Integer, L1House> tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getHouseTableList();
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public L1House getHouseTable(int houseId) {
    L1House tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getHouseTable(houseId);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void updateHouse(L1House house) {
    this._lock.lock();
    try {
      this._storage.updateHouse(house);
    } finally {
      this._lock.unlock();
    } 
  }
}
